package CutLoad.cookies
{
	import flash.events.Event;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	
	/**
	 * 常用操作的声音方法
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 
	 */
	public class CSound
	{
		private var sound:Sound;
		private var playSoundStart:Number=0;
		private var soundC:SoundChannel=null;
		//
		public function CSound(sound:Sound)
		{
			this.sound=sound;
		}
		/**
		 * 播放一次 
		 * @param start 开始处
		 * 
		 */		
		public function playOnce(start:Number=0):void{
			//trace("playOnce..")
			if(soundC!=null) stop();
			playSoundStart=start;
			soundC=sound.play(playSoundStart);
		}
		/**
		 * 循环播放 
		 * @param start 开始处
		 * 
		 */		
		public function playLoop(start:Number=0):void{
			//trace("playLoop..")
			if(soundC!=null) stop();
			playSoundStart=start;
			soundC=this.sound.play(start);
			soundC.addEventListener(Event.SOUND_COMPLETE,playCmpt);
		}
		public function stop():void{
			soundC.stop();
			if(soundC.hasEventListener(Event.SOUND_COMPLETE)) soundC.removeEventListener(Event.SOUND_COMPLETE,playCmpt);
		}
		//放完
		private function playCmpt(e:Event):void{
			soundC.removeEventListener(Event.SOUND_COMPLETE,playCmpt);
			soundC=this.sound.play(playSoundStart);
			soundC.addEventListener(Event.SOUND_COMPLETE,playCmpt);
		}
	}
}